<template>
    <div class="view-main">
        <div class="view-body">

            <el-form :model="addForm" ref="addForm" :rules="addRules" label-width="100px" class="demo-ruleForm">
                <el-form :inline="true"  class="demo-form-inline">

            <el-form-item label="案卷名称" prop="name">
                <el-input  v-model="addForm.name" placeholder="案卷名称"></el-input>
            </el-form-item>


            <el-form-item label="办案部门" prop="department_value">
                <el-select  placeholder="办案部门" v-model="addForm.department_value">
                    <el-option v-for="item in department" :label="item.label" :value="item.value"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="案卷类型" prop="type_value">
                <el-select  placeholder="案卷类型" v-model="addForm.type_value">
                    <el-option v-for="item in type" :label="item.label" :value="item.value"></el-option>
                </el-select>
            </el-form-item>
        </el-form>

            <el-form :inline="true"  class="demo-form-inline">
                <el-form-item label="案卷编号" prop="code">
                    <el-input  v-model="addForm.code" placeholder="案卷编号"></el-input>
                </el-form-item>

                <el-form-item label="案发时间"  prop="crimeTime">
                    <el-col :span="20">
                        <el-date-picker type="date" placeholder="案发时间" v-model="addForm.crimeTime" style="width: 100%;"></el-date-picker>
                    </el-col>
                </el-form-item>

                <el-form-item label="案卷级别"  prop="level_value" >
                    <el-select  placeholder="案卷级别" v-model="addForm.level_value">
                        <el-option v-for="item in level" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>

            <el-form :inline="true"  class="demo-form-inline">
                <el-form-item label="案发地点"  prop="address">
                    <el-input v-model="addForm.address" placeholder="案发地点"></el-input>
                </el-form-item>

                <el-form-item label="案发原由" prop="reason">
                    <el-col :span="30">
                        <el-input  v-model="addForm.reason" placeholder="案发原由"></el-input>
                    </el-col>
                </el-form-item>
            </el-form>

            <el-form :inline="true"  class="demo-form-inline" label-width="100px">
                <el-form-item label="案卷描述" prop="description">
                    <el-input v-model="addForm.description" placeholder="案卷描述" ></el-input>
                </el-form-item>
            </el-form>

                <el-form-item>
                    <el-button type="primary" @click="submitForm('addForm')">确认</el-button>
                    <el-button @click="resetForm('addForm')">重置</el-button>
                </el-form-item>
            </el-form>

        </div>
    </div>
</template>

<script>
    import { checkLoginName, checkPhone, checkEmail, checkObj, isEmpty, stringFormat } from '../../utils/util'


    export default {
        name: 'user',
        data() {
            return {
                addForm: {
                    name: '',
                    code: '',
                    crimeTime: '',
                    address: '',
                    reason: '',
                    description: '',
                    department_value: "",
                    type_value: "",
                    level_value: "",
                },
                department: [
                    { value: "0", label: "部门1" },
                    { value: "1", label: "部门2" },
                    { value: "2", label: "部门3" }
                ],
                type: [
                    { value: "0", label: "案卷类型1" },
                    { value: "1", label: "案卷类型2" },
                    { value: "2", label: "案卷类型3" }
                ],
                level: [
                    { value: "0", label: "案卷级别1" },
                    { value: "1", label: "案卷级别2" },
                    { value: "2", label: "案卷级别3" }
                ],
                addRules: {
                    // trigger: 'blur'鼠标失去焦点时触发事件
                    name: [{ required: true, message: '请输入储物柜名称', trigger: 'blur' }],
                    code: [{ required: true, message: '请输入储物柜编号', trigger: 'blur' }],
                    crimeTime: [{ required: true, message: '请输入储物柜地址', trigger: 'blur' }],
                    address: [{ required: true, message: '请输入储物柜端口', trigger: 'blur' }],
                    reason: [{ required: true, message: '请输入储物柜类型', trigger: 'blur' }],
                    description: [{ required: true, message: '请输入储物柜类型', trigger: 'blur' }]
                },
                url: {
                    // page: '/jzm/jzStore',
                    // update: '/jzm/jzStore/update/{0}',
                    // insert: '/jzm/jzStore/insert',
                    // delete: '/jzm/jzStore/delete/{0}',
                }
            }
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        let _form = JSON.parse(JSON.stringify(this.addForm))
                            console.log(_form)
                            console.log("222")
                            var address = this.url.insert
                            this.$http.put(address, _form).then(() => {
                            //    刷新，
                            })
                            alert('submit!');
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
                console.log("111")
            }
        }
    }
</script>